package cn.kgc.student.service.impl;

import cn.kgc.student.pojo.Classes;
import cn.kgc.student.dao.ClassesMapper;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import cn.kgc.student.utils.Page;
import javax.annotation.Resource;
import cn.kgc.student.vo.ClassesParam;
import com.alibaba.dubbo.config.annotation.Service;
import cn.kgc.student.service.ClassesService;
/**
* 描述：班级 服务实现层接口
* @author 魏耀
* @date 2019/07/22
*/
@Service(interfaceClass=ClassesService.class,timeout = 60000,retries = 2,version = "1.2")
public class ClassesServiceImpl implements ClassesService{
	@Resource
	private ClassesMapper classesMapper;
 	
 	/**
    * 描述：根据Id获取Classes对象
    * @param id
    */
    public Classes findById(Serializable id){
    	return classesMapper.findById(id);
    }
    /**
    * 描述：获取所有的Classes对象
    */
    public List<Classes> findAll(){
		System.out.println("被调用了一次");
    	return classesMapper.findAll();
    }

	/**
    * 描述：新增保存Classes对象
    */
    public int save(Classes classes){
    	return  classesMapper.save(classes);
    }

	/**
    * 描述：根据Id删除Classes对象
    * @param id
    */
    public int delete(Serializable id){
    	return  classesMapper.delete(id);
    }
	
	/**
    * 描述：更新Classes对象
    */
    public int update(Classes classes){
    	return  classesMapper.update(classes);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Classes> query(ClassesParam param){
    	return  classesMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(ClassesParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = classesMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = classesMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
